<template>
  <el-dialog :visible="visible" title="查询方案" @close="close">
    <el-container class="tab-container">
      <el-main class="main">
        <collapse-tab class="main-search">
          <el-form
            :inline="true"
            :model="queryCondition"
            label-width="80px"
            @keyup.enter.native="query"
          >
            <!--查询条件区 -->
            <el-form-item label="名称">
              <p-input v-model="queryCondition.name" class="form-item" />
            </el-form-item>
            <el-form-item style="float:right;">
              <list-button-query :page-code="pageCode" />
            </el-form-item>
            <div class="clearfix" />
          </el-form>
        </collapse-tab>
        <el-card class="main-report">
          <div>
            <list-button-refresh :page-code="pageCode" />
            <list-button-add :page-code="pageCode" @click="add" />
            <list-button-remove :page-code="pageCode" />
            <div style="clear:both;" />
          </div>
          <div style="margin-top:5px;">
            <div>
              <columns-controller v-model="columnList" :table-key="tableKey" />
            </div>
            <el-table
              v-loading="loading"
              :data="tableData"
              style="width: 100%"
              highlight-current-row
              border
              @sort-change="handleSortChange"
              @current-change="handleRowChange"
              @selection-change="handleSelectionChange"
              @row-dblclick="handleDoubleClickRow"
            >
              <el-table-column type="selection" width="55" />
              <el-table-column
                v-for="(item, index) in showCols"
                :key="index"
                :label="item.label"
                :prop="item.prop"
                :show-overflow-tooltip="item.showOverflowTooltip"
                :width="item.width"
                :formatter="item.formatFunc"
                :sortable="item.sortable"
              />
              <el-table-column fixed="right" label="操作" width="250">
                <template slot-scope="scope">
                  <el-button type="text" @click="doAdvanceQuery(scope.row.content)">查询</el-button>
                  <table-button-modify :id="scope.row.id" :page-code="pageCode" />
                  <table-button-remove :id="scope.row.id" :page-code="pageCode" />
                  <el-button type="text" @click="saveAs(scope.row)">另存为</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <list-pager
            :page-num="pageInfo.pageNum"
            :page-size="pageInfo.pageSize"
            :page-total="pageTotal"
          />
        </el-card>
        <detail
          ref="detail"
          :entity-code="queryCondition.entityCode"
          :field-list="fieldList"
          @ok="handleDetailSave"
          @doQuery="doAdvanceQuery"
        />
      </el-main>
    </el-container>
  </el-dialog>
</template>

<script>

import { listMixin } from '@/mixin/listMixin'
import Detail from './detail'
const MODULE_CODE = 'support'
const ENTITY_TYPE = 'advanceQueryScheme'
export default {
  name: ENTITY_TYPE,
  components: { Detail },
  mixins: [listMixin],
  data() {
    return {
      entityType: ENTITY_TYPE,
      moduleCode: MODULE_CODE,
      // eslint-disable-next-line no-eval
      api: eval('this.$api.' + MODULE_CODE + '.' + ENTITY_TYPE),
      pageCode: MODULE_CODE + ':' + ENTITY_TYPE + ':',
      visible: false,

      queryCondition: {},
      columnList: [
        // prop label show 必须定义， width/showOverflowTooltip/formatFunc/sortable 需要的话定义
        { prop: 'name', label: '名称', show: true },
        { prop: 'orderNo', label: '排序号', show: true }

      ],
      // 高级查询字段列表
      fieldList: []

    }
  },
  methods: {
    show(entityCode, fieldList) {
      this.queryCondition.entityCode = entityCode
      this.fieldList = fieldList
      this.getTableData()
      this.visible = true
    },
    // 关闭窗口
    close() {
      this.visible = false
    },
    // 执行高级查询
    doAdvanceQuery(condition) {
      this.$emit('advanceQuery', condition)
      this.close()
    },
    // 另存为
    saveAs(row) {
      this.$refs.detail.clone(row)
    }

  }
}
</script>

<style lang="scss" scoped>
.tab-container {
  $item-width: 200px;
  padding: 15px;
  .aside {
    min-width: 180px;
    background-color: white;
  }
  .main {
    .main-search {
      .form-item {
        width: $item-width;
      }
    }
    .main-report {
      margin-top: 10px;
    }
  }
}
</style>
